package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVo;
import com.itheima.health.vo.UserVO;
import com.itheima.health.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public UserVO findUserInfoByUsername(String username) {
        UserVO userVo = baseMapper.findUserInfoByUsername(username);
        List<RoleVo> roles =  baseMapper.findRolesByUid(userVo.getId());
        for (RoleVo roleVo : roles) {
            List<Permission> permissionList =   baseMapper.findPermission(roleVo.getId());
            roleVo.setPermission(permissionList);


        }
        userVo.setRoles(roles);
        return userVo;

    }
}
